<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>
			兄弟海鲜管理系统
		</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<meta http-equiv="refresh" content="60">
		<link rel="stylesheet" href="./css/x-admin.css" media="all">
		<link href="css/xtiper.css" type="text/css" rel="stylesheet" />
		<script src="js/xtiper.min.js" type="text/javascript"></script>
		<script type="text/javascript" src="js/rmodal.js"></script>
		<style>
			.xtipfeedback {
				background-color: #E6E6E6;
				width: 100%;
				height: 22px;
				margin-top: 10px;
			}
		</style>
	</head>

	<body onload="findall()">
		<div class="x-nav">
			<span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>订单管理</cite></a>
              <a><cite>已完成订单列表</cite></a>
            </span>
			<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>
		<div class="x-body">
			<div style="margin-bottom: 15px;">
				<label class="layui-form-label">查询订单</label>
				<div class="layui-input-inline">
					<input type="text" id="orderRandom" name="orderRandom" placeholder="订单号" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-input-inline" style="width:80px">
					<button class="layui-btn" onclick="search()"><i class="layui-icon">&#xe615;</i></button>
				</div>
			</div>
			<xblock>
				<div style="height: 38px;">
					<span class="x-right" style="line-height:40px">共有数据：<a id="total" name="total"></a> 条</span>
				</div>
			</xblock>
			<table class="layui-table">
				<thead>
					<tr>
						<th>
							<input type="checkbox" name="" value="">
						</th>
						<th>
							ID
						</th>
						<th>
							评论者
						</th>
						<th>
							评论内容
						</th>
						<th>
							评论订单号
						</th>
						<th>
							回复状态
						</th>
						<th>
							操作
						</th>
					</tr>
				</thead>

				<tbody id="commentslist">
				</tbody>
			</table>

			<div id="page">
			</div>
		</div>
		<script src="./lib/layui/layui.js" charset="utf-8"></script>
		<script src="./js/x-layui.js" charset="utf-8"></script>

		<script type="text/javascript">
			function findall() {
				var url = 'http://127.0.0.1:8080/comment/findall.do?page=1&size=10';
				var settings = {
					"url": url,
					"method": "GET",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					},
				};
				$.ajax(settings).done(function(response) {
					$('#total').text();
					var a = 1;
					var b = 1;
					var sum=0;
					var tol=0;
					var msg = "";
					var html = "";
					for(var i = 0; i < response.total; i++) {
						if(response.list[i].commentState == "未回复") {
							msg += '<tr> <td>';
							msg += '<input type=\"checkbox\" value=\"' + response.list[i].orderId + '\" id=\"commentId\" name=\"commentId\"></td> ';
							msg += '<td>' + a + '</td> ';
							msg += '<td>' + response.list[i].orders.customer.customerName + '</td>';
							msg += ' <td style=\"width: 100px;text-overflow:ellipsis;\"> ' + response.list[i].commentContent + '</td>';
							msg += ' <td><u style=\"cursor:pointer\"  onclick=\"detailorder(' + response.list[i].orders.orderId + ')\">' + response.list[i].orders.orderId + '</u></td>';
							msg += ' <td ><span class=\"layui-btn layui-btn-normal layui-btn-mini\" style=\"background-color: #AC2925;\">' + response.list[i].commentState + '</span></td>';
							msg += '<td class=\"td-manage\"> ';
							msg += ' <a title=\"编辑\"  class=\"ml-5\" style=\"text-decoration:none\" onclick=\"feedback(' + response.list[i].commentId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/修改.png\" style="width: 25;\" height=\"25\"></i>';
							msg += '</a></td> </tr>';
							a++;
						} else {
							tol=a+b
							html += '<tr> <td>';
							html += '<input type=\"checkbox\" value=\"' + response.list[i].orderId + '\" id=\"commentId\" name=\"commentId\"></td> ';
							html += '<td>' +tol + '</td> ';
							html += '<td>' + response.list[i].orders.customer.customerName + '</td>';
							html += ' <td style=\"width: 100px;text-overflow:ellipsis;\"> ' + response.list[i].commentContent + '</td>';
							html += ' <td><u style=\"cursor:pointer\"  onclick=\"detailorder(' + response.list[i].orders.orderId + ')\">' + response.list[i].orders.orderId + '</u></td>';
							html += ' <td ><span class=\"layui-btn layui-btn-normal layui-btn-mini\">' + response.list[i].commentState + '</span></td>';
							html += '<td class=\"td-manage\"> ';
							html += ' <a title=\"查看回复\"  class=\"xbutton\" style=\"text-decoration:none\" onclick=\"checkfeedback(' + response.list[i].commentId + ')\">';
							html += ' <i class=\"layui-icon\"><img src=\"images/订单确认.png\" style="width: 30;\" height=\"30\"></i>';
							html += '</a></td> </tr>';
							b++;
						}
						sum++;
					}
					msg = msg + html;
					$("#commentslist").html(msg);
					$("#total").text(sum);
				});
			}
		</script>
		<script type="text/javascript">
			layui.use(['layer'], function(){
              layer = layui.layer;//弹出层
            });
			function detailorder(orderId) {
				var url = 'http://127.0.0.1:8080/order/finddetail?orderId=' + orderId;
				$.ajax({
					type: "post", //post方式传输，比get更加密安全
					url: url, //请求地址
					success: function(data) {
						for(var i = 0; i < data.length; i++) {
							sessionStorage.setItem(i, JSON.stringify(data[i]));
						}
						x_admin_show("订单详情",'./detailshow.html','600','500');
					},
					error: function() {
						alert("失败");
					}
				})
			}
		</script>

		<script type="text/javascript">
			function search() {
				var orderRandom = $("#orderRandom").val();
				var url = 'http://127.0.0.1:8080/comment/findFeedback?commentId=' + orderRandom;
				var settings = {
					"url": url,
					"method": "GET",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					},
				};
				$.ajax(settings).done(function(response) {
					if(response != "") {
						$('#commentslist').empty();
						var sum = 0;
						var a=1;
						var msg = "";
						msg += '<tr> <td>';
						msg += '<input type=\"checkbox\" value=\"' + response.list[i].orderId + '\" id=\"commentId\" name=\"commentId\"></td> ';
						msg += '<td>' + a + '</td> ';
						msg += '<td>' + response.list[i].orders.customer.customerName + '</td>';
						msg += ' <td style=\"width: 100px;text-overflow:ellipsis;\"> ' + response.list[i].commentContent + '</td>';
						msg += ' <td><u style=\"cursor:pointer\"  onclick=\"detailorder(' + response.list[i].orders.orderId + ')\">' + response.list[i].orders.orderId + '</u></td>';
						msg += ' <td ><span class=\"layui-btn layui-btn-normal layui-btn-mini\" style=\"background-color: #AC2925;\">' + response.list[i].commentState + '</span></td>';
						msg += '<td class=\"td-manage\"> ';
						if(response.list[i].commentState == "未回复") {
							msg += ' <a title=\"编辑\"  class=\"ml-5\" style=\"text-decoration:none\" onclick=\"feedback(' + response.list[i].commentId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/修改.png\" style="width: 25;\" height=\"25\"></i>';
							msg += '</a></td> </tr>';
						} else {
							html += ' <a title=\"查看回复\"  class=\"xbutton\" style=\"text-decoration:none\" onclick=\"checkfeedback(' + response.list[i].commentId + ')\">';
							html += ' <i class=\"layui-icon\"><img src=\"images/订单确认.png\" style="width: 30;\" height=\"30\"></i>';
							html += '</a></td> </tr>';
						}
						$("#commentslist").html(msg);
						$("#total").text(sum);
					} else {
						alert("失败");
					}
				})
			}
		</script>
		<script src="js/jquery.min.js"></script>

		<script type="text/javascript">
			function feedback(commentId) {
				xtip.win({
					tip: '<textarea  id="feedbackContent" name="feedbackContent" cols="25" rows="5" placeholder="请输入回复内容" style="border: 1px solid #E6E6E6;"></textarea>',
					icon: 'w',
					title: '回复评论',
					btn: ['确认回复', '取消回复'],
					btn1: function() {
						var ins = $("#feedbackContent").val();
						var url = 'http://127.0.0.1:8080/comment/update?commentId=' + commentId
						var settings = {
							"url": url,
							"method": "POST",
							"timeout": 0,
							"headers": {
								"Content-Type": "application/json"
							},
							"data": JSON.stringify({
								"feedbackContent": ins
							}),
						};

						$.ajax(settings).done(function(response) {
							xtip.msg("回复成功", {
								times: 1
							});
							location.href = "./comment-list.html";
						});
					}
				})
			}
		</script>
		<script type="text/javascript">
			function checkfeedback(commentId) {
				var url = 'http://127.0.0.1:8080/comment/findFeedback?commentId=' + commentId
				var settings = {
					"url": url,
					"method": "GET",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					},
				};
				$.ajax(settings).done(function(response) {
							var msg = "";
							msg += '<div class=\"xtipfeedback\">';
							msg += '<span>评论:<a>' + response.comments.commentContent + '</a></span> </div>';
							msg += '<div class=\"xtipfeedback\">';
							msg += '<span >回复:</span> </div> <div >';
							msg += '<textarea id="feedbackContent"  cols=\"25\" rows=\"5\"  style=\"border: 1px solid #E6E6E6;\"  >' + response.feedbackContent + '</textarea> </div>';
							msg += '<div class=\"xtipfeedback\">';
							msg += '<span>回复时间:<a>' + response.feedbackTime + '</a></span> </div>';
							xtip.win({
								tip: msg,
								icon: 's',
								title: '查看回复',
								btn: ['修改回复', '关闭'],
								btn1: function() {
									var ins = $("#feedbackContent").val();
									if (ins!=response.feedbackContent) {
										var url = 'http://127.0.0.1:8080/comment/update?commentId=' + commentId;
									var settings = {
										"url": url,
										"method": "POST",
										"timeout": 0,
										"headers": {
											"Content-Type": "application/json"
										},
										"data": JSON.stringify({
											"feedbackContent": ins
										}),
									};

									$.ajax(settings).done(function(response) {
										xtip.msg("修改回复成功", {
											times: 1
										});
									});
									}
								}});
							});
				}
		</script>
	</body>

</html>